<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- <eHeader :permission="permission" />
      <crudOperation :permission="permission" /> -->
    </div>
    <!--表格渲染-->
    <!-- <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <el-table-column type="selection" width="55" />
      <el-table-column prop="departName" label="名称" />
      <el-table-column prop="desc" label="描述" />
      <el-table-column prop="enabled" label="状态" align="center">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.enabled"
            active-color="#409EFF"
            inactive-color="#F56C6C"
            @change="changeEnabled(scope.row, scope.row.enabled)"
          />
        </template>
      </el-table-column> -->
    <!--   编辑与删除   -->
    <!-- <el-table-column
        v-permission="['admin','job:edit','job:del']"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation
            :data="scope.row"
            :permission="permission"
          />
        </template>
      </el-table-column>
    </el-table> -->
    <!--分页组件-->
    <pagination />
    <!--表单渲染-->
    <!-- <eForm :job-status="this.job_status" /> -->
  </div>
</template>

<script>
import crudJob from '@/api/system/dept'
// import eHeader from './module/header'
// import eForm from './module/form'
import CRUD, { presenter } from '@crud/crud'
// import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
// import udOperation from '@crud/UD.operation'

export default {
  name: 'Dept',
  components: { pagination },
  cruds() {
    return CRUD({
      title: '部门',
      url: 'config/dept/getlist',
      crudMethod: { ...crudJob }
    })
  },
  mixins: [presenter()],
  // 数据字典
  data() {
    return {
      permission: {
        add: ['admin', 'job:add'],
        edit: ['admin', 'job:edit'],
        del: ['admin', 'job:del']
      },
      job_status: [
        { key: 'true', display_name: '正常' },
        { key: 'false', display_name: '禁用' }
      ]
    }
  },
  methods: {
    // 改变状态
    changeEnabled(data, val) {
      this.$confirm('此操作将 "' + this.job_status[val] + '" ' + data.departName + '部门, 是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // eslint-disable-next-line no-undef
        crudJob.edit(data).then(() => {
          // eslint-disable-next-line no-undef
          this.crud.notify(this.job_status[val] + '成功', 'success')
        }).catch(err => {
          data.enabled = !data.enabled
          console.log(err.data.message)
        })
      }).catch(() => {
        data.enabled = !data.enabled
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
 ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
